package com.ruoyi.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.MerchantMarketingApplications;
import com.ruoyi.merchant.service.IMerchantMarketingApplicationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家营销活动申请Controller
 * 
 * @author ruoyi
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/merchant/applications")
public class MerchantMarketingApplicationsController extends BaseController
{
    @Autowired
    private IMerchantMarketingApplicationsService merchantMarketingApplicationsService;

    /**
     * 查询商家营销活动申请列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:applications:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantMarketingApplications merchantMarketingApplications)
    {
        startPage();
        List<MerchantMarketingApplications> list = merchantMarketingApplicationsService.selectMerchantMarketingApplicationsList(merchantMarketingApplications);
        return getDataTable(list);
    }

    /**
     * 导出商家营销活动申请列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:applications:export')")
    @Log(title = "商家营销活动申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantMarketingApplications merchantMarketingApplications)
    {
        List<MerchantMarketingApplications> list = merchantMarketingApplicationsService.selectMerchantMarketingApplicationsList(merchantMarketingApplications);
        ExcelUtil<MerchantMarketingApplications> util = new ExcelUtil<MerchantMarketingApplications>(MerchantMarketingApplications.class);
        util.exportExcel(response, list, "商家营销活动申请数据");
    }

    /**
     * 获取商家营销活动申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:applications:query')")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") String appId)
    {
        return success(merchantMarketingApplicationsService.selectMerchantMarketingApplicationsByAppId(appId));
    }

    /**
     * 新增商家营销活动申请
     */
    @PreAuthorize("@ss.hasPermi('merchant:applications:add')")
    @Log(title = "商家营销活动申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantMarketingApplications merchantMarketingApplications)
    {
        return toAjax(merchantMarketingApplicationsService.insertMerchantMarketingApplications(merchantMarketingApplications));
    }

    /**
     * 修改商家营销活动申请
     */
    @PreAuthorize("@ss.hasPermi('merchant:applications:edit')")
    @Log(title = "商家营销活动申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantMarketingApplications merchantMarketingApplications)
    {
        return toAjax(merchantMarketingApplicationsService.updateMerchantMarketingApplications(merchantMarketingApplications));
    }

    /**
     * 删除商家营销活动申请
     */
    @PreAuthorize("@ss.hasPermi('merchant:applications:remove')")
    @Log(title = "商家营销活动申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable String[] appIds)
    {
        return toAjax(merchantMarketingApplicationsService.deleteMerchantMarketingApplicationsByAppIds(appIds));
    }
}
